import 'package:flutter/material.dart';

abstract class Builder {
  Widget build();
}

abstract class Director {
  Widget buildPage();
}

class BuilderPatterns extends StatelessWidget {
  const BuilderPatterns({super.key});

  @override
  Widget build(BuildContext context) {
    return ProfileDirector().buildPage();
  }
}

class ProfilePage extends StatelessWidget {
  const ProfilePage({
    super.key,
    required this.avatar,
    required this.name,
    required this.details,
  });
  final Widget avatar;
  final Widget name;
  final Widget details;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Profile Builder Pattern Example')),
      body: Column(
        children: [avatar, name, details],
      ),
    );
  }
}

class AvatarBuilder implements Builder {
  @override
  Widget build() {
    return const CircleAvatar(
      radius: 50,
      backgroundImage: NetworkImage('https://picsum.photos/200'),
    );
  }
}

class NameBuilder implements Builder {
  @override
  Widget build() {
    return const Text(
      'John Doe',
      style: TextStyle(
        fontSize: 24,
        fontWeight: FontWeight.bold,
      ),
    );
  }
}

class DetailsBuilder implements Builder {
  @override
  Widget build() {
    return ListView(
      shrinkWrap: true,
      padding: const EdgeInsets.all(8),
      children: const [
        Text('Email: demo@example.com'),
        Text('Phone:123312323'),
      ],
    );
  }
}

class ProfileDirector implements Director {
  @override
  Widget buildPage() {
    return ProfilePage(
      avatar: AvatarBuilder().build(),
      name: NameBuilder().build(),
      details: DetailsBuilder().build(),
    );
  }
}
